#ifndef SOCKET_H
#define SOCKET_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <iostream>
#include <string.h>
#include <arpa/inet.h>
#include <string>



class Socket{

 public:

  Socket(int family, int protcol);

  Socket();

  virtual ~Socket() {}

  int Bind(int port);

  int Close();

  std::string GetPeerAddress();
  
  void SetPeerAddress(sockaddr_in addr);

  virtual int Listen();//tcp only

  virtual Socket* Accept();//tcp only

  virtual int Connect(char* address, int port);//tcp only

  virtual void SetPeerAddress(char* address, int port);//udp only

  virtual int Receive(void* buffer, int length) = 0;

  virtual int Send(const void* buffer, int length) = 0;

  static const int BACK_LOG_NUM = 100;
    
   
 protected:

  int m_sockfd;//socket file descriptor

  int m_type;//udp or tcp

  int m_family;//ipv4 or ipv6

  int m_port;
    
  struct sockaddr_in m_host_addr;//addr struct of this socket

  struct sockaddr_in m_peer_addr;//addr struct for peer socket

  socklen_t peer_addr_length;


};

#endif
